package service.impl;

import mapper.StudentMapper;
import model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.StudentService;

import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
    //自动注入dao层对象studentMapper
    @Autowired
    StudentMapper studentMapper;
    @Override
    public int add(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public int edit(Student newStudent) {
        return studentMapper.update(newStudent);
    }

    @Override
    public List<Student> findAll() {
        return studentMapper.findAll();
    }

    @Override
    public void delete(int id) {
         studentMapper.delete(id);
    }

    @Override
    public Student getById(int id) {
        return studentMapper.getById(id);
    }

    @Override
    public boolean login(String name, String password) {
        //如果select where name=,and password=?能查到记录，说明登录成功，
        return studentMapper.selectByNameAndPassword(name, password) != null;
    }

    @Override
    public List<Student> selectByPage(int fromIndex, int pageSize) {
        return studentMapper.selectByPage(fromIndex,pageSize);
    }
}
